<?php

App::uses('AppModel', 'Model');

class Category extends AppModel
{
    const STATUS_INACTIVE = 0;
    const STATUS_ACTIVE = 1;
    const KAOISAMA = '6337fa64-cb11-11e3-9ffa-fc4dd44a2aac';
    const ADMIN = 'a2d2df43-9130-11e3-8702-642737866159';
    const ASOCIADO = 'aa0ac014-02c0-11e4-995e-24b6fdfa405b';
    const FACILITADOR = '3a35cb42-cb11-11e3-9ffa-fc4dd44a2aac';
    const SUPERVISOR = '6dbc4e61-7110-11e4-b249-fc4dd44a2aac';
    const SOLOLECTURA = 'cd024450-7149-11e4-9dc4-24b6fdfa405b';
    const MIGRACION = 'b88b5729-ac16-11e4-a6f9-24b6fdfa405b';

    public $useTable = 'categories';

    public static function getCategories($category) {
        $categories = array();
        switch ($category) {
            case self::KAOISAMA:
                $categories = array(
                    array('text' => __('Kaoisama'), 'value' => self::KAOISAMA),
                    array('text' => __('Migración'), 'value' => self::MIGRACION),
                    array('text' => __('Administrador'), 'value' => self::ADMIN),
                    array('text' => __('Supervisor'), 'value' => self::SUPERVISOR),
                    array('text' => __('Facilitador'), 'value' => self::FACILITADOR),
                    array('text' => __('Solo lectura'), 'value' => self::SOLOLECTURA),
                    array('text' => __('Asociado'), 'value' => self::ASOCIADO),
                );
                break;
            case self::ADMIN:
                $categories = array(
                    array('text' => __('Administrador'), 'value' => self::ADMIN),
                    array('text' => __('Supervisor'), 'value' => self::SUPERVISOR),
                    array('text' => __('Facilitador'), 'value' => self::FACILITADOR),
                    array('text' => __('Solo lectura'), 'value' => self::SOLOLECTURA),
                    array('text' => __('Asociado'), 'value' => self::ASOCIADO),
                );
                break;
            case self::SUPERVISOR:
                $categories = array(
                    array('text' => __('Asociado'), 'value' => self::ASOCIADO),
                );
                break;
            case self::SOLOLECTURA:
                $categories = array(
                    array('text' => __('Asociado'), 'value' => self::ASOCIADO),
                );
                break;
            case self::FACILITADOR:
                $categories = array(
                    array('text' => __('Asociado'), 'value' => self::ASOCIADO),
                );
                break;
        }
        return $categories;
    }

    /**
     * Obtenemos la categoria identificada por su ID
     * @param string $id
     * @return array
     */
    public function getById($id) {
        $this->id = $id;
        return $this->read();
    }

    /**
     * Obtenemos las categorias habilitadas
     * @return array Arreglo de categorias activas
     */
    public function getEnabled() {
        $filters = array(
            'fields' => array(
                'name as text',
                'id as value'
            ),
            'conditions' => array(
                'status' => self::STATUS_ACTIVE
            ),
        );
        $records = $this->find('all', $filters);
        return $this->flatArray($records);
    }

    public function getPublicEnabled() {
        $filters = array(
            'fields' => array(
                'name as text',
                'id as value'
            ),
            'conditions' => array(
                'id !=' => self::KAOISAMA,
                'status' => self::STATUS_ACTIVE
            ),
        );
        $records = $this->find('all', $filters);
        return $this->flatArray($records);
    }

}
